package com.datastructure.test.numKlensubstrrepeats;

import java.util.Arrays;

public class NumKLenSubstrRepeats {

    public static void main(String[] args) {
        NumKLenSubstrRepeats numKLenSubstrRepeats = new NumKLenSubstrRepeats();
        int createfunonyoka = numKLenSubstrRepeats.numKLenSubstrRepeats("ababab", 3);
        System.out.println(createfunonyoka);
    }

    public int numKLenSubstrRepeats (String s, int k) {
        // write code here
        int length = s.length();
        int num = 0;
        String temp;
        for (int i = 0; i < length - k+1; i++) {
            temp=s.substring(i,i+k);
            if(!judge(temp)){
                num++;
            }
        }
        return num;
    }

    private boolean judge(String temp) {
        byte[] bytes = temp.getBytes();
        Arrays.sort(bytes);
        for (int i = 0; i < bytes.length-1; i++) {
            if(bytes[i]==bytes[i+1]){
                return false;
            }
        }
        return true;
    }

    public String replaceSpace (String s) {
        // write code here
       return s.replaceAll(" ","%20");
    }
}
